package bTree.LeetCode;

public class 位1的个数 {
    public int hammingWeight(int n) {
        StringBuilder sb=new StringBuilder();
        while (n!=0){
            int i = n % 2;
            sb.append(i);
            n/=2;
        }
        int result=0;
        String string = sb.reverse().toString();
        for (int i = 0; i < string.length(); i++) {
            if(string.charAt(i)=='1'){
                result++;
            }
        }
        return result;
    }
}
